<?php
namespace jy_baidu;
defined('BY_JYA') or exit('error');
/*
	推送文章机制
*/
class set_data extends \plugin{
	public function upnews($title='',$content='',$origin_url='',$cover_images='',$is_original=1){
		$setting=$this->plugin_setting('setting');
		$app_token=$setting['app_token'];
		$app_id=$setting['app_id'];
		if(!$app_token){
			exi('app_token未填写','error');
		}
		if(!$client_key){
			exi('app_id未填写','error');
		}
		$url = 'http://baijiahao.baidu.com/builderinner/open/resource/article/publish?app_token='.$app_token.'&app_id='.$app_id; //发布图文接口的URL
		$post=array('title'=>$title,'content'=>$content,'origin_url'=>$origin_url,'cover_images'=>$cover_images,'is_original'=>$is_original);
		$post=ijson_encode($post);
		$res = cfc('http')->ihttp_request($url,$post);
		$shuju=json_decode($res['content'],true);
		if($shuju['errno']){
			exi('发布百家号文章失败：'.$shuju['errmsg'],'error');
		}
		return $shuju['data'];
	}
}